<?php
/**
 * Translation Class
 * @author Sokha RUM
 */
class Translation {
    static private $instance = null;
    private $objects = array();
    /**
     * Construction of Translation class
     */
    private function __construct() {
    }
    
    /**
     * Getting the instance of this class
     */
    static function getInstance() {
    	if (Translation::$instance == null) {
    		Translation::$instance = new Translation();
    	}
    	return Translation::$instance;
    } 
    
    /**
     * merge the objects
     * @param array $new_obj
     */
    function merge_object($new_obj) {
    	$this->objects = array_merge($this->objects, $new_obj);
    }
    
    /**
     * getting Objects
     */
    function getObjects() {
    	return $this->objects;
    }
    
    /**
     * Getting the value of an object
     * @param String $obj_code
     */
    function value($obj_code, $escape_html=true) {
    	if (!key_exists($obj_code, $this->objects)) {
    		$value = "%".$obj_code."%";
    	} else { 
    	    $value = $this->objects[$obj_code];
    	}
    	if ($escape_html) {
    		return htmlspecialchars($value);
    	} else {
    		return $value;
    	}
    }
}
?>